package com.atguigu.eud_teacher.controller.front;
import com.atguigu.commonutils.R;
import com.atguigu.eud_teacher.entity.ChapterEntity;
import com.atguigu.eud_teacher.entity.CourseEntity;
import com.atguigu.eud_teacher.entity.vo.SubjectAndDescVo;
import com.atguigu.eud_teacher.feignclient.CourseFeignVideo;
import com.atguigu.eud_teacher.service.ChapterService;
import com.atguigu.eud_teacher.service.CourseService;
import com.atguigu.eud_teacher.service.VideoService;
import com.atguigu.eud_teacher.vo.CourseInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: Administrator
 * @date: 2021-04-19 9:35
 */
@CrossOrigin
@RestController
@Api(tags = "--前台课程条件查询信息API")
@RequestMapping("/vue-admin-template/subjectConditionSelect")
public class CourseFrontController {

    @Autowired
    private CourseService courseService;

    @Autowired
    private ChapterService chapterService;

    @Autowired
    private CourseFeignVideo courseFeignVideo;




    //分页加条件插叙，条件写vo类
    @ApiOperation(value="课程查询")
    @PostMapping("/selectCourseList/{page}/{limit}")
    public R selectCourseList(@ApiParam(name = "page", value = "当前页码", required = true)
                              @PathVariable long page,
                              @ApiParam(name = "limit", value = "每页记录数", required = true)
                              @PathVariable long limit,
                              @ApiParam(name = "subjectAndDescVo", value = "查询对象", required = false)
                              @RequestBody(required = false) SubjectAndDescVo subjectAndDescVo){
        Map<String, Object> stringObjectMap = courseService.conditionSelect(page, limit, subjectAndDescVo);
        return R.ok().data("stringObjectMap",stringObjectMap);
    }

    //根据课程course_id获取课程基本信息包括描述和章节小节
    @ApiOperation(value="课程详情")
    @GetMapping("/getCourseDetailsInfo/{courseId}")
    public R getCourseDetailsInfo(@PathVariable String courseId){
        CourseInfoVo courseInfoVo=courseService.getBaseCourseInfo(courseId);
        List<ChapterEntity> allChaptersAndVideos = chapterService.findAllChaptersAndVideos(courseId);
        return R.ok().data("courseInfoVo",courseInfoVo).data("allChaptersAndVideos",allChaptersAndVideos);
    }

    //根据videoid获取视频地址，名称，凭证,这里用了远程调用
    @ApiOperation(value="阿里云小节视频在线播放")
    @GetMapping("/getChapterVideoById/{videoSourceId}")
    public R getChapterVideoById(@PathVariable String videoSourceId){
        return courseFeignVideo.getVideoPlayAuth(videoSourceId);
    }

    //根据课程course_id获取课程基本信息
    @ApiOperation(value="根据id课程信息")
    @GetMapping("/getCourseInfo/{courseId}")
    public com.atguigu.commonutils.ordervo.CourseInfoVo getCourseInfo(@PathVariable String courseId){
        com.atguigu.commonutils.ordervo.CourseInfoVo courseInfoVo = courseService.getBaseCourseInfoo(courseId);
        return courseInfoVo;
    }
}
